package com.zhaojy.poc.service.impl;

import com.pi4j.io.gpio.*;
import com.zhaojy.poc.frame.GpioEntity;
import com.zhaojy.poc.service.GpioExampleService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

/**
 * Created by zhaojiuyang1 on 16/3/12.
 */
public class GpioExampleServiceImpl implements GpioExampleService {

    @Resource
    private GpioEntity gpioEntity;
    private GpioPinDigitalOutput pin;

    @Override
    public void up() {
        pin.high();
    }

    @Override
    public void down() {
        pin.low();
    }

    @Override
    public void init() {
        // provision gpio pin #01 as an output pin and turn on
        GpioPinDigitalOutput pin = gpioEntity.getGpioController().provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED", PinState.LOW);
        this.pin = pin;
        // set shutdown state for this pin
        pin.setShutdownOptions(true, PinState.LOW);
    }

}
